WAIT Statement Action Suspends program execution while monitoring the status of a machine input port. Syntax WAIT portnumber, and-expression% , xor-expression% Remarks The WAIT statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- portnumber An unsigned integer expression between 0 and 65,535, inclusive, that is the number of the machine input port. and-expression% An integer expression that is repeatedly combined with the bit pattern received at the port, using an AND operator; when the result is nonzero, the WAIT statement stops monitoring the port, and program execution resumes with the next program statement. xor-expression% Can be used to turn bits on and off in the received bit pattern before the AND operation is applied. Argument Description ---------------------------------------------------------------------------- applied. The WAIT statement is an enhanced version of the INP function; it suspends execution until a specified bit pattern is input from an input port, using the following four steps. - 1. The data byte read from the port is combined, using an XOR operation, with xor-expression%. If xor-expression% is omitted, it is assumed to be 0. - 2. The result is combined with and-expression% using an AND operation. - 3. If the result is zero, the first two steps are repeated. - 4. If the result is nonzero, execution continues with the next program statement. It is possible to enter an infinite loop with the WAIT statement if the input port fails to develop a non-zero bit pattern. In this case, you must manually restart the machine. - The following example program line illustrates the syntax of the WAIT statement. WAIT HandShakePort, 2 This statement will cause BASIC to do an AND operation on the bit pattern received at the DOS I-O port HandShakePort with the bit pattern represented by 2 (00000010). Note The WAIT statement is not available in OS-2 protected mode. See Also INP, OUT Example The following example demonstrates the use of the WAIT statement. ' Open and close the port at the proper baud rate. OPEN "COM1.9600,N,8,1,BIN" FOR RANDOM AS #1 CLOSE #1 PortNum% = &H3F8 'COM1 NonPrintCharMask% = 96 ' Wait until there's some activity on COM1. ' Mask out characters less than 32 for the first input character. LOCATE 12, 15. PRINT "Waiting for a printable input character. " WAIT PortNum%, NonPrintCharMask% ' Once a printable character comes in, execution continues. DO 'Get a character from the port and evaluate. A% = INP(PortNum%) SELECT CASE A% CASE 7 Character$ = " BELL " CASE 8 Character$ = "BACK SPACE " CASE 9 Character$ = " TAB " CASE 13 Character$ = " CR " CASE 32 Character$ = " SPACE " CASE 127 Character$ = " DEL " CASE IS < 31, IS > 127 Character$ = "unprintable" CASE ELSE Character$ = SPACE$(5) + CHR$(A%) + SPACE$(5) END SELECT LOCATE 12, 15 ' Report the input character. PRINT "Numeric Value ASCII Character" LOCATE 14, 20 PRINT A%; TAB(50); Character$ IF A% > 127 THEN STOP LOCATE 23, 25 PRINT "Press ANY key to quit." LOOP WHILE INKEY$ = "" END